package com.xneure.utils.bean;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

public class StringPrintWriter extends PrintWriter{
	private StringWriter sw;

	private StringPrintWriter(Writer w) throws FileNotFoundException{
		super(w);
		this.sw = (StringWriter)w;
	}

	public static StringPrintWriter newPrintWriter(){
		try{
			return new StringPrintWriter(new StringWriter());
		}catch(FileNotFoundException e){
			return null;
		}
	}

	@Override
	public void write(char[] buf,int off,int len){
		sw.write(buf,off,len);
	}

	public String getValue(){
		String string = sw.toString();
		sw.getBuffer().setLength(0);
		return string;
	}
}
